<?php
class Upload extends Controller {
	public function __construct() {
		parent::__construct();
	}

	public function index() {
		if($this->input->post('upload1') !='') {
			$filefield = $this->input->post('upload1');
			$ebook_name = $this->input->post("ebook-name");
		}
		$config['upload_path'] = './upload/';
		$config['allowed_types'] = 'pdf|chm';
		$config['max_size'] = '15000';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
		$config['overwrite'] = true;
		$this->load->library('upload', $config);
		$this->upload->initialize($config);
		if ( ! $this->upload->do_upload($filefield)) {
			$error = array('error' => $this->upload->display_errors());
			var_dump($error);
			//$this->load->view('upload_form', $error);
		}
		else {
			$data = array('upload_data' => $this->upload->data());
			$ebook_path = $data['upload_data']['file_name'];
			$ebook = array(
				'ebook_name'=>$ebook_name,
				'ebook_path'=>$ebook_path,
				'catagory_id'=>0
			);
			$this->load->model("Ebook_model","ebook");
			$this->ebook->create($ebook);
			var_dump($data);
			$this->load->view('upload_success', $data);
		}
	}
}
?>